package com.ag.wsq.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;

import com.ag.bean.TbUser;
import com.ag.wsq.dao.SchedDAO;

public class OneSchedServiceImpl {
	private static Logger logger = Logger.getLogger(OneSchedServiceImpl.class);
	private SchedDAO schedDAO;
	
	public List oneSched(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date now = new Date();
		String timeStart =sdf.format(now);
		String timeEnd = timeStart;
		logger.info("oneSched start--------");
		
		String cql = "from TbSched p join fetch p.tbUser join fetch p.tbDuty" +
				" where p.tbDuty.duId = '值班领导'";
		if (timeStart != null && timeStart.length() > 0) {
			cql += " and p.id.scTime >= :timeStart";			
		}
		if (timeEnd != null && timeEnd.length() > 0) {
			cql += " and p.id.scTime <= :timeEnd";
		}
		List result = null;
		try {
			result = schedDAO.getOneSched(cql, timeStart, timeEnd);
		} catch (Exception e) {

			e.printStackTrace();
		}
		System.out.println("------------------------------------");	
		System.out.println("result  = " + result.size());
		return result;
	}
	
	public List daiban(){
		logger.info("daiban start--------");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date now = new Date();
		String timeStart =sdf.format(now);
		String timeEnd = timeStart;
		
		String cql = "from TbSched p join fetch p.tbUser join fetch p.tbDuty" +
				" where p.tbDuty.duId = '带班领导'";
		if (timeStart != null && timeStart.length() > 0) {
			cql += " and p.id.scTime >= :timeStart";			
		}
		if (timeEnd != null && timeEnd.length() > 0) {
			cql += " and p.id.scTime <= :timeEnd";
		}
		List result = null;
		try {
			result = schedDAO.getOneSched(cql, timeStart, timeEnd);
		} catch (Exception e) {

			e.printStackTrace();
		}
		System.out.println("------------------------------------");	
		System.out.println("result  = " + result.size());
		return result;
	}

	public SchedDAO getSchedDAO() {
		return schedDAO;
	}

	public void setSchedDAO(SchedDAO schedDAO) {
		this.schedDAO = schedDAO;
	}
}
